const app = getApp()
const $api = require('../../../utils/api.js').API;
Page({
    data: {
        jobCate:[],
    },
    onLoad: function(){
      this.getJobCate()
    },
    getJobCate:function(){
      var data = {}
      var that = this
      $api.get('job/list',data).then(res =>{
          //请求成功
          if(res.data.code == 1){
            that.cateData(res.data.data)
          }
      })
    },
    checkboxChange(e) {
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2]; //上一个页面
      var route = prevPage.route;
      var post = e.detail.value;
      post = post.join(',');
      if(route == 'pages/login/company'){
        let session = wx.getStorageSync('formSession');
        session['job'] = post;
        wx.setStorageSync('formSession',session);
        prevPage.setData({
          form:session
        })
      }
      else if(route == 'pages/user/company/index'){
        var form = prevPage.data.form
        form.job = post
        prevPage.setData({
          form:form
        })
      }
      else{
        let session = wx.getStorageSync('session');
        session['post'] = post;
        wx.setStorageSync('session',session);
      }
    },
    cateData:function(cate){
      var that = this
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2]; //上一个页面
      var route = prevPage.route;
      if(route == 'pages/login/company'){
        var session = wx.getStorageSync('formSession');
        var post = session['job']
      }
      else if(route == 'pages/user/company/index'){
        var post = prevPage.data.form.job
      }
      else{
        var session = wx.getStorageSync('session');
        var post = session['job']
      }
      if(post){
        let post1 = post.split(',')
        for(var x in cate){
          if(post1.indexOf(cate[x]['name']) >= 0){
            cate[x]['checked'] = true
          }
        }
      }
      that.setData({
        jobCate:cate
      })
    },
    onShareAppMessage: function() {
      return {
          title: "天意美业直通车",
          path: "/pages/index/index?puid="+wx.getStorageSync('uid')
      };
    }
});